<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./css/style.css">
    <title>注册学生账号</title>
    
    <link rel="stylesheet" type="text/css" href="easyui/1.3.4/themes/default/easyui.css" />
    <script type="text/javascript" src="js/axios.js"></script>
    <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="easyui/1.3.4/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui/1.3.4/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
<h1>申请经费</h1>
<div class="info">
    <div class="form">
        <div class="left">
            <div class="form-item">
                <div class="label">项目id</div>
                ：
                <input type="text" id="pid">
            </div>
            <div class="form-item">
                <div class="label">申请数额</div>
                ：
                <input type="number" id="amount" maxlength="10">
            </div>
            <div class="form-item">
                <div class="label">申请时间</div>
                ：
                <input type="date" id="date" class="date-picker">
            </div>
            <div class="form-item">
                <div class="label" >发起人</div>
                ：
                <input type="text" id="approvalsponsor" value="" readonly>
            </div>
        </div>
    </div>
    <div class="link" style="align-self: start">
        <div class="link-item" id="send-request">添加</div>
        <div class="link-item" id="reset">重置</div>
    </div>

</div>
<script>
    //使申请时间为当前日期
    var defaultDate = document.querySelectorAll('.date-picker');
            for (var i = 0; i<defaultDate.length; i++) {
                defaultDate[i].valueAsDate = new Date();
            }
    const user = JSON.parse(localStorage.getItem("userinfo"));
    $("#approvalsponsor").attr("value",user.teacherName);
    const pid = $("#pid");
    const amount = $("#amount");
    const date = $("#date");
    const sendRequest = $("#send-request");
    const reset = $("#reset");
    
    sendRequest.click(function () {
        axios.post("http://localhost:8080/fundingApproval/save", {
            projectId: pid.val(),
            amount: amount.val(),
            approvalDate: date.val(),
            approvalStatus: "待审核",
            approvalSponsor: user.teacherName
        }).then(({data}) => {
            alert("添加成功！");
            top.location.reload(true);
        }).catch(err => {
            alert("请填写正确项目id！");
        })
    })
    
    reset.click(function () {
        name.val("");
        address.val("");
        phone.val("");
        fax.val("");
    })

</script>
</body>
</html>